package com.cq.androidtools.jetpack.WorkManager

import android.content.Context
import android.util.Log
import androidx.work.Data
import androidx.work.Worker
import androidx.work.WorkerParameters

/**
 * 作者: CQ
 * 日期: 2021-05-24
 * 说明:
 */
class MyWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
    private val TAG = "MyWorker1"
    override fun doWork(): Result {
        Log.e(TAG,"work执行了")
        Thread.sleep(1000)
        //获取mainActivity传入进来的数据
        val jettData = inputData.getString("WorkerActivity")
        Log.i(TAG, "work中取到了----- $jettData")
        //把任务中的数据回传到activity中
        val outData = Data.Builder().putString("name", "陈").build()
        return Result.success(outData)
    }
}

class MyWorker2(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
    private val TAG = "MyWorker2"
    override fun doWork(): Result {
        Log.e(TAG,"work执行了")
        Thread.sleep(1000)
        //获取mainActivity传入进来的数据
        val jettData = inputData.getString("WorkerActivity")
        Log.i(TAG, "work中取到了----- $jettData")
        //把任务中的数据回传到activity中
        val outData = Data.Builder().putString("name", "张").build()
        return Result.success(outData)
    }
}

class MyWorker3(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
    private val TAG = "MyWorker3"
    override fun doWork(): Result {
        Log.e(TAG,"work执行了")
        Thread.sleep(1000)
        //获取mainActivity传入进来的数据
        val jettData = inputData.getString("WorkerActivity")
        Log.i(TAG, "work中取到了----- $jettData")
        //把任务中的数据回传到activity中
        val outData = Data.Builder().putString("name", "刘").build()
        return Result.success(outData)
    }
}

class MyWorker4(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
    private val TAG = "MyWorker4"
    override fun doWork(): Result {
        Log.e(TAG,"work执行了")
        Thread.sleep(1000)
        //获取mainActivity传入进来的数据
        val jettData = inputData.getString("WorkerActivity")
        Log.i(TAG, "work中取到了----- $jettData")
        //把任务中的数据回传到activity中
        val outData = Data.Builder().putString("name", "刘").build()
        return Result.success(outData)
    }
}

class MyWorker5(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
    private val TAG = "MyWorker5"
    override fun doWork(): Result {
        Log.e(TAG,"work执行了")
        Thread.sleep(1000)
        //获取mainActivity传入进来的数据
        val jettData = inputData.getString("WorkerActivity")
        Log.i(TAG, "work中取到了----- $jettData")
        //把任务中的数据回传到activity中
        val outData = Data.Builder().putString("name", "刘").build()
        return Result.success(outData)
    }
}